package org.dean.webapps.projectname.logger;

import org.apache.log4j.Logger;
import org.apache.log4j.spi.ThrowableInformation;

/**
 * Created by IntelliJ IDEA.
 * User: dean
 * Date: 9/22/11
 * Time: 9:39 AM
 * To change this template use File | Settings | File Templates.
 */
public class ApplicationLogger {

    private static Logger infoLog = Logger.getLogger("marketplace_info");
    private static Logger transactionLog = Logger.getLogger("marketplace_transaction");
    private static Logger errorLog = Logger.getLogger("marketplace_error");
    private static Logger paypalTransLog = Logger.getLogger("marketplace_paypal_transaction.log");
    private static Logger paypalErrorLog = Logger.getLogger("marketplace_paypal_error.log");

    /**
      * Log important server information.
      *
      * @param desc
      */
     public static void logInfo(String desc) {
         infoLog.info(desc);
     }

     /**
      * Log important server information.
      *
      * @param desc
      * @param ex
      */
     public static void logInfo(String desc, Throwable ex) {
         infoLog.info(desc, ex);
     }

     /**
      * Log important error message that can be handled by server or not severe.
      *
      * @param desc
      */
     public static void logError(String desc) {
         errorLog.info(desc);
     }

     /**
      * Log important error message that can be handled by server or not severe.
      *
      * @param desc
      * @param ex
      */
     public static void logError(String desc, Throwable ex) {
         errorLog.info(desc, ex);
     }

     /**
      * Log all types of interaction with search engines. Transactions with Database, etc.
      *
      * @param desc
      */
     public static void logTransaction(String desc) {
         transactionLog.info(desc);
     }

     /**
      * Log important paypal error message that can be handled by server or not severe.
      *
      * @param desc
      */
     public static void logPaypalError(String desc) {
         paypalErrorLog.info(desc);
     }

     /**
      * Log important paypal error message that can be handled by server or not severe.
      *
      * @param desc
      * @param ex
      */
     public static void logPaypalError(String desc, Throwable ex) {
         paypalErrorLog.info(desc, ex);
     }

     /**
      * Log all types of paypal interaction with search engines. Transactions with Database, etc.
      *
      * @param desc
      */
     public static void logPaypalTrans(String desc) {
         paypalTransLog.info(desc);
     }

    public static String getStringData(Throwable th){
        ThrowableInformation thInfo = new ThrowableInformation(th);
        String[] arr = thInfo.getThrowableStrRep();
        StringBuffer sb = new StringBuffer();
        for (String s : arr){
            sb.append(String.format("%s%n", s));
        }
        return sb.toString();
    }
}
